package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.CheckItem;
import com.itheima.dao.IPermissionDao;
import com.itheima.dao.Permission;
import com.itheima.dao.Role;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.IPermissonService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = IPermissonService.class)
public class PermissionServiceImpl implements IPermissonService {

    @Autowired
    private IPermissionDao permissionDao;

    @Override
    public PageResult findPageByCondition(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage,pageSize);

        Page<Permission> page = permissionDao.findPageByCondition(queryString);
        long total = page.getTotal();
        List<Permission> rows = page.getResult();
        return new PageResult(total,rows);
    }

    /**
     * 删除功能
     * @param id
     */
    @Override
    public void delete(Integer id) {
        permissionDao.delete(id);
    }

    /**
     * 通过ID查询
     * @param id
     * @return
     */
    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    @Override
    public void update(Permission permission) {
        permissionDao.edit(permission);
    }

    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }


    /**
     * 添加功能
     * @param permission
     */
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }


    // 根据角色ID查找权限ID
    @Override
    public List<Integer> findPermissionIdsByRoleId(Integer id) {
        return permissionDao.findPermissionIdsByRoleId(id);
    }



}
